﻿using System.Collections.Generic;
using DirectoryServicesProtocolsExtensions.LdapConnection.MetaData;
using DirectoryServicesProtocolsExtensions.MetaData;
using DirectoryServicesProtocolsExtensions.MetaData.SemanticAttributeGroupings;

namespace IntegrationTests
{
    using System.DirectoryServices.Protocols;
    using DirectoryServicesProtocolsExtensions.LdapConnection;

    public abstract class LdapTest 
    {
        private static ILdapConnectionPropertiesContainer ldapConnectionPropertiesContainer;
        protected static LdapConnection LdapConnection;
        protected static LdapMetaMapFactory  LdapMetaMapFactory;
        protected static readonly GuidEncodedAttributeGroup GuidEncodedAttributeGroup = 
            new GuidEncodedAttributeGroup(new List<string> {"objectGUID"});
        protected static readonly SidEncodedAttributeGroup SidEncodedAttributeGroup = 
            new SidEncodedAttributeGroup(new List<string>{"objectSID"});
        protected static readonly Int64DateTimeEncodedAttributeGroup Int64DateTimeEncodedAttributeGroup =
            new Int64DateTimeEncodedAttributeGroup(new List<string>
        {
            "lastLogonTimestamp", "lastLogon", "pwdLastSet", "accountExpires"
        });
        protected static readonly StringEncodedIntAttributeGroup StringEncodedIntAttributeGroup = 
            new StringEncodedIntAttributeGroup(new List<string> {"userAccountControl"});
        protected static readonly AttributesWhichMayRequireExpansionGroup AttributesWhichMayRequireExpansionGroup = 
            new AttributesWhichMayRequireExpansionGroup(new List<string> {"member"});

        
        protected LdapTest()
        {
            InitializeCodeUnderTest();
        }

        private static void InitializeCodeUnderTest()
        {
            ldapConnectionPropertiesContainer = new MockFabrikamActiveDirectoryConnectionPropertiesContainer();
            var ldapConnectionFactory = new LdapConnectionFactory(ldapConnectionPropertiesContainer);
            LdapConnection = ldapConnectionFactory.Create();
            LdapMetaMapFactory = new LdapMetaMapFactory(
                new LdapMetaMapFactoryInitializationValues(
                    GuidEncodedAttributeGroup,
                    SidEncodedAttributeGroup,
                    Int64DateTimeEncodedAttributeGroup,
                    StringEncodedIntAttributeGroup,
                    AttributesWhichMayRequireExpansionGroup));

        }
    }
}
